module.exports = {
    state: {
        routePath: '/',
        redirPath: undefined,
        site: {},
        webar: {
            show: 'default'
        },
        webarSearch: undefined
    },
    mutations: {
        pushRoute: (state, path) => state.routePath = path ,
        redirect: (state, path) => state.redirPath = path ,
        doRedirect (state) {
            if(state.redirPath) {
                $router.push(state.redirPath)
                state.redirPath = undefined
            } else {
                $router.push('/')
            }
        },
        menu: (state, data) => state.site = data,
        webar: (state, config) => state.webar = config,
        webarNav: (state, nav) => state.webar.nav = nav
    },
    getters: {
        currentPath: (state) => {
            return state.routePath
        },
        redirectPath: (state) => {
            return state.redirPath
        },
        routes: (state) => {
            return _.map(state.site.tree, (item) => {
                return {
                    path: item.path,
                    name: item.name,
                    component: httpVueLoader(item.page),
                    meta: {
                        title: item.label || item.name,
                        webar: item.webar || 'default',
                        protect: item.protect
                    }
                }
            })
        },
        menuName: (state) => {
            return (n) => {
                return state.site.menus[n - 1].name
            }
        },
        menuItems: (state) => {
            return (n) => {
                return _.filter(state.site.tree, {menu: n.toString()})
            }
        },
        webar: (state) => {
            return state.webar
        }
    }
}